﻿#include "stackplateinfowid.h"
#include <QMessageBox>
#include <QTimer>

StackPlateInfoWid::StackPlateInfoWid(QWidget *parent)
	: QWidget(parent)
{
	ui.setupUi(this);
	ui.spinBox_4->setValue(0);
	ui.spinBox_4->setDisabled(true);
	ui.groupBox->setDisabled(true);
	ui.groupBox_2->setDisabled(true);
}

StackPlateInfoWid::~StackPlateInfoWid()
{
}

bool StackPlateInfoWid::Init(StackPlate* plate)
{
	if (plate == nullptr) {
		return false;
	}
	m_plate = plate;
	ui.label_2->setText(m_plate->GetPlateId());
	ShowInfo();
	return true;
}

void StackPlateInfoWid::ShowInfo()
{
	m_state.clear();
	m_state = m_plate->GetPlateStateInfo();
	ui.comboBox->setCurrentIndex(m_state.plate ? 1 : 0);
	ui.spinBox_4->setValue(m_state.num);
	if (m_state.sku.valied) {
		ui.lineEdit->setText(m_state.sku.skuNo);
		ui.spinBox->setValue(m_state.sku.size.length);
		ui.spinBox_2->setValue(m_state.sku.size.width);
		ui.spinBox_3->setValue(m_state.sku.size.height);
		ui.lineEdit_2->setText(QString::number(m_state.stack.type));
		ui.lineEdit_3->setText(m_state.stack.name);
		ui.spinBox_5->setValue(m_state.stack.max);
		ui.spinBox_6->setValue(m_state.stack.ceng);
	} else {
		ui.lineEdit->setText("");
		ui.spinBox->setValue(0);
		ui.spinBox_2->setValue(0);
		ui.spinBox_3->setValue(0);
		ui.lineEdit_2->setText(0);
		ui.lineEdit_3->setText(0);
		ui.spinBox_5->setValue(0);
		ui.spinBox_6->setValue(0);
	}

	QTimer::singleShot(1000, [&]() {
		ShowInfo();
		});
}


